package cn.kgc.ssm.service.impl;

import cn.kgc.ssm.dto.ActivityPageDTO;
import cn.kgc.ssm.entity.Activity;
import cn.kgc.ssm.mapper.ActivityMapper;
import cn.kgc.ssm.response.ResponseResult;
import cn.kgc.ssm.service.ActivityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 课工场
 * @date 2024/11/19
 * @description
 */
@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;


    @Override
    public ResponseResult activityPage(ActivityPageDTO activityPageDTO) {

        PageHelper.startPage(activityPageDTO.getPage(), activityPageDTO.getLimit());

        List<Activity> tableData = activityMapper.selectActivities(activityPageDTO.getPublisher());

        PageInfo<Activity> activityPageInfo = new PageInfo<>(tableData);

        long total = activityPageInfo.getTotal();


        return ResponseResult.success().count(total).data(tableData);
    }

    @Override
    public ResponseResult addActivity(Activity activity) {

        activityMapper.insertActivity(activity);

        return ResponseResult.success();
    }

    @Override
    public ResponseResult editActivity(Activity activity) {

        activityMapper.updateActivity(activity);
        return ResponseResult.success();
    }

    @Override
    public ResponseResult removeActivity(List<Integer> ids) {

        activityMapper.deleteActivities(ids);

        return ResponseResult.success();
    }

    @Override
    public ResponseResult activityList(Integer limit) {

       List<Activity> activityList =  activityMapper.selectActivityList(limit);
        return ResponseResult.success().data(activityList);
    }
}
